package leetcode.editor.cn;

import org.junit.Test;
import org.omg.CORBA.INTERNAL;

import java.util.LinkedList;
import java.util.List;

public class Main {

    public int mySqrt(int x) {
        if(x<=1) return x;
        long tmp;
        int left=0,right=x/2+1,mid,ans=-1;
        //从右向左缩小窗口
        while(left<=right){
            mid=(left+right)/2;
            tmp=(long)mid*mid;
            if(tmp==x) return mid;
            else if(tmp>x) right=mid-1;//mid肯定不是结果
            else {
                ans=mid;
                left=mid;//mid可能是结果
            }
        }
        return ans;
    }
    @Test
    public  void Solution69() {
        mySqrt(8);
    }
    @Test
    public  void Solution199() {
        TreeNode root=new TreeNode(-13);
        TreeNode p1 = new TreeNode(1);
        TreeNode p2 = new TreeNode(2);
        TreeNode p3 = new TreeNode(3);
        TreeNode p4 = new TreeNode(4);
        TreeNode p5 = new TreeNode(5);
//        root.left=p1;
//        root.right=p2;
        p1.left=p2;
        p1.right=p3;
        p2.left=p5;
        System.out.println(new Solution199().rightSideView(p1));
    }
    @Test
    public  void Solution54() {
        System.out.println(new Solution54().spiralOrder(new int[][]{
                {1,2,3}

        }));
        System.out.println(new Solution54().spiralOrder(new int[][]{
                {1,2,3}
                ,{4,5,6},
                {7,8,9},
                {7,8,9}
        }));
    }
    public  void Solution42() {
        System.out.println(new Solution42().trap(new int[]{0,1,0,2,1,0,1,3,2,1,2,1}));
    }

    @Test
    public  void Solution23() {
        ListNode[] listNodes=new ListNode[6];
        ListNode p5=new ListNode(5);
        ListNode p4=new ListNode(4,p5);
        ListNode p1=new ListNode(1,p4);
        ListNode p44=new ListNode(4);
        ListNode p3=new ListNode(3,p44);
        ListNode p11=new ListNode(1,p3);
        ListNode p6=new ListNode(6);
        ListNode p2=new ListNode(2,p6);
        ListNode p7=new ListNode(7);
        ListNode p8=new ListNode(8);
        ListNode p9=new ListNode(9);
        listNodes[0]=p1;
        listNodes[1]=p11;
        listNodes[2]=p2;
        listNodes[3]=p7;
        listNodes[4]=p8;
        listNodes[5]=p9;
        System.out.println(new Solution23().mergeKLists(listNodes));
    }
    @Test
    public  void Solution33() {
        System.out.println(new Solution33().search(new int[]{4,5,6,7,0,1,2},0));
    }
    @Test
    public  void Solution25() {
        System.out.println(new Solution25());
    }
    @Test
    public  void Solution91() {
        System.out.println(new Solution91().numDecodings("111"));
    }
    @Test
    public  void Solution207() {
        new Solution207().canFinish01(4,new int[][]
                {{1,0},{2,1},{3,2},{0,2}});
    }
    @Test
    public  void Solution450() {
        new Solution450().deleteNode(
                new Codec().deserialize("5,3,6,2,4,null,7"),
                3
        );

    }
    @Test
    public  void Solution224() {
        new Solution224().calculate("1 + 1");
    }
    @Test
    public  void Solution297() {
        TreeNode q = new Codec().deserialize("1,2,3,null,null,4,5,6,7");
        System.out.println(new Codec().serialize(q));
    }
    @Test
    public  void Solution151() {
        System.out.println(new Solution151().reverseWords("the sky    is blue"));
        System.out.println(new Solution151().reverseWords("  the sky is   "));
        System.out.println(new Solution151().reverseWords("3c      2zPeO dpIMVv2SG    1AM       o       VnUhxK a5YKNyuG     x9    EQ  ruJO       0Dtb8qG91w 1rT3zH F0m n G wU"));
    }
        @Test
    public  void Solution124() {

        TreeNode root=new TreeNode(-13);
        TreeNode p1 = new TreeNode(1);
        TreeNode p2 = new TreeNode(2);
        TreeNode p3 = new TreeNode(3);
        TreeNode p4 = new TreeNode(4);
        TreeNode p5 = new TreeNode(5);
//        root.left=p1;
//        root.right=p2;
        p1.left=p3;
        p1.right=p4;
        p2.left=p5;
        System.out.println(new Solution124().maxPathSum(root));
    }
}
